package com.huazi.user.registration.servlet;

import com.huazi.user.registration.entity.Doctor_Info;
import com.huazi.user.registration.service.DoctorInfoServicei;
import com.huazi.user.registration.service.Imp.DoctorInfoservice;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 查看挂号医生信息的方法
 */
public class DoctorServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        DoctorInfoServicei service = new DoctorInfoservice();//new出对应的service的服务
        String orp = req.getParameter("opr");//获得操作符·然后根据操作符进行操作
        String caozuo = req.getParameter("caozuo");
        if (caozuo == null) {//做个判断如果为空则赋默认值
            caozuo = "";
        }
        if (caozuo.equals("name")) {
            String name = req.getParameter("name");
            Doctor_Info doctor = service.FindByNames(name);
            String names = doctor.getName();
            req.setAttribute("doctor", doctor);
            req.getRequestDispatcher("Wang/doctor/doctorInfo.jsp").forward(req, resp);
        } else {
            if (orp.equals("huazi")) {
                orp = "华子科";
            } else {
                orp = "骨科";
            }
            List<Doctor_Info> list = service.loockInfo(orp);
            req.setAttribute("list", list);
            //将查询到的医生信息保存到req中并且转发连接
            req.getRequestDispatcher("Wang/registration/subscribeInfo.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
